<extend name="Layout/ins_page" />
<block name="content">
	{:W('PageHeader/simple',array('name'=>$tag_name))}
	<div class="oprator-panel">
		<a class="btn" onclick="go_return_url()">返回</a>
		<div class="split"></div>
		<a id="btn_add" class="btn">新增</a>
		<a id="btn_save" class="btn">保存</a>
		<span class="l">|</span>
		<a id="btn_del" class="btn btn-del">删除</a>
	</div>
	<div class="sub-frame">
		<div class="sub-sidebar gray">
			<?php echo $menu ?>
		</div>
		<div class="sub-content gray">
			<form id="form_data" name="form_data" method="post">
				<input type="hidden" name="id" id="id">
				<input type="hidden" name="pid" id="pid" value="0">
				<input type="hidden" name="ajax" id="ajax" value="0">
				<input type="hidden" name="opmode" id="opmode" value="">
				<select name="tag_list" id="tag_list" class="hidden">
					{:fill_option($tag_list)}
				</select>
				<div class="layui-sub-form-item">
					<label class="layui-form-label" for="name">名称：</label>
					<div class="layui-input-block">
						<input type="text" id="name" name="name" check="required" info="请输入名称" class="layui-input">
					</div>
				</div>
				<if condition="$has_pid">
					<div class="layui-sub-form-item">
						<label class="layui-form-label" for="tag_name">父节点*：</label>
						<div class="layui-input-block">
							<div class="input-group">
								<input name="tag_name" class="layui-input val" id="tag_name" type="text" info="请选择父节点" check="required" />
								<span class="input-group-btn">
									<button class="btn" id="btn_select_pid" type="button">
										选择
									</button> </span>
							</div>
						</div>
					</div>
				</if>
				<div class="layui-sub-form-item">
					<label class="layui-form-label" for="sort">排序：</label>
					<div class="layui-input-block">
						<input type="text" id="sort" name="sort" class="layui-input">
					</div>
				</div>
				<div class="layui-sub-form-item">
					<label class="layui-form-label" for="is_del">状态：</label>
					<div class="layui-input-block x-select  col-10">
						<select   name="is_del" id="is_del" class="layui-input">
							<option value="">请选择</option>
							<option  value="0">启用</option>
							<option value="1">禁用</option>
						</select>
					</div>
				</div>
				<div class="layui-sub-form-item">
					<label class="layui-form-label" for="remark">备注：</label>
					<div class="layui-input-block">
						<textarea id="remark" name="remark" rows="5" class="layui-textarea"></textarea>
					</div>
				</div>
			</form>
		</div>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		layui.use(['global'], function() {
			var $ = layui.jquery;

			$(".sub-sidebar .tree_menu  a").click(function() {
				$(".sub-sidebar .tree_menu  a").removeClass("active");
				$(this).addClass("active");
				send_ajax("{:U('system_tag/read')}", "id=" + $(this).attr("node"), function(data) {
					showdata(data);
				});
				return false;
			});

			function showdata(result) {
				for (var s in result.data) {
					set_val(s, result.data[s]);
				}
				if ($("#pid").val() == 0) {
					$("#tag_name").val("根节点");
				} else {
					$("#tag_name").val($("#tag_list option[value='" + $("#pid").val() + "']").text());
				}
				$("#opmode").val("edit");
			};

			$("#btn_add").on('click', function() {
				winopen("{:U('SystemTag/add',array('controller'=>$controller))}", 560, 470);
			});

			$("#btn_save").on('click', function() {
				if ($("#opmode").val() == "") {
					layer.msg("请选择文件夹或新增");
				}
				send_form("form_data", "__SELF__", "__SELF__", function(ret) {
					if (ret.status) {
						layer.msg(ret.info);
						location.reload(true);
					} else {
						layer.msg(ret.info);
						return false;
					}
				});
			});

			$('#btn_del').on('click', function() {
				if ($(".sub-sidebar a.active").length == 0) {
					layer.msg('请选择要删除的数据');
					return false;
				}
				if ($(".sub-sidebar a.active").parent().find(".tree_menu").html() != undefined) {
					layer.msg('有子数据不能删除');
					return false;
				}
				//信息框-例2
				$("#opmode").val("del");
				layer.msg('确定要删除吗?', {
					time : 0,
					btn : ['确定', '取消'],
					yes : function(index) {
						var vars = $("#form_data").serialize();
						send_ajax("__SELF__", vars, function(ret) {
							if (ret.status) {
								layer.msg(ret.info, function() {
									location.reload(true);
								});
							} else {
								layer.msg(ret.info);
								return false;
							}
						});
					},
					no : function(index) {
						layer.close(index);
					}
				});
			});

			$('#btn_select_pid').on('click', function() {
				winopen("{:U('winpop')}", 560, 470);
			});
		});

		function select_pid() {
			winopen("{:U('system_tag/winpop?controller='.CONTROLLER_NAME)}", 560, 470);
		}

	</script>
</block>